<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!--文件和图片上传页面-->
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>图片文件上传</h5>
                </div>
                <div class="ibox-content">
                    <div class="form-group">
                        <label class="font-noraml">上传</label>
                        <div class="file-loading">
                            <input id="filePath" name="filePath" class="form-control" type="file">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<script type="text/javascript">
    var prefix=ctx +"/pro/img";

    function submitHandler() {
        if ($.validate.form()) {
            uploadFile();
        }
    }

    function uploadFile() {
        var formData = new FormData();
        if ($('#imgUrl')[0].files[0] == null) {
            $.modal.alertWarning("请先选择文件路径");
            return false;
        }
        formData.append('imgName', $("#imgName").val());
        formData.append('img', $('#imgUrl')[0].files[0]);
        $.ajax({
            url: prefix + "/add",
            type: 'post',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            dataType: "json",
            success: function(result) {
                $.operate.successCallback(result);
            }
        });
    }
</script>
</body>
</html>